﻿using NXIBLL;
using NXIDAL;
using NXModel;
using System.Drawing;
using System.Security.Cryptography;
using System.Xml.Linq;
using System;
using Dto;

namespace NXBLL
{
    public class NXPBLL : INXBLL
    {
        public NXPBLL(IbaseDAL<LoginModel> dal,IbaseDAL<YHJModel> dal2)
        {
            Dal = dal;
            Dal2 = dal2;
        }

        public IbaseDAL<LoginModel> Dal { get; }
        public IbaseDAL<YHJModel> Dal2 { get; }
        public Task<int> shanchu(int i)
        {
            var quer = Dal2.GetAllAsync().FirstOrDefault(a => a.Yid == i);
            return Dal2.DeleteAsync(quer);
        }

        public async Task<int> tianjia(YHJModel model)
        {
            bool var = Dal2.GetAllAsync().Any(x => x.Yname == model.Yname);
            if (var)
            {
                return -1;
            }
            else
            {
                return await Dal2.AddAsync(model);
            }
        }

        public Myhjdhbc xisnshi(int index,int size)
        {
            var lml = Dal2.GetAllAsync();
            var quer = from a in lml
                       select new
                       {
                          a.Yid,
                          a.Yname,
                          a.SM,
                          a.Isdeldet,
                          a.Levsl
                       };
            
            int c = quer.Count();
            var d = quer.OrderBy(x => x.Yid).Skip((index - 1) * size).Take(size).ToList();
            return new Myhjdhbc { Count = c, Members = d };
        }
        public LoginModel Login(string name, string pwd)
        {
            LoginModel quer = Dal.GetAllAsync().FirstOrDefault(x => x.Uname == name);
            if (quer == null)
            {
                quer = new LoginModel { Uid = -1 };
            }
            else
            {

                quer = new LoginModel { Uid = -2 };


            }
            return quer;
        }
    }
}
